package com.ccp.dev.workflow.bpmimpl.skipimpl;

import com.ccp.dev.workflow.bpminterface.ISkipCondition;
import com.ccp.dev.workflow.model.TaskOpinion;
import com.ccp.dev.workflow.service.TaskOpinionService;
import org.flowable.task.api.Task;

import javax.annotation.Resource;
import java.util.List;


/**
 * 之前审批过后跳过
 * @author jiayeuqiao
 */
public class ApproveUserSkipCondition implements ISkipCondition {

	@Resource
	TaskOpinionService taskOpinionService;

	@Override
	public boolean canSkip(Task task) {
		String assignee=task.getAssignee();

		//获取之前的审批人，从审批历史中获取。
		List<TaskOpinion> list= taskOpinionService.getByProcInstId(task.getProcessInstanceId());
		for(TaskOpinion opinion:list){
			Short status=opinion.getCheckStatus();
			if(status.equals(TaskOpinion.STATUS_AGREE)
					|| status.equals(TaskOpinion.STATUS_ABANDON)
					|| status.equals(TaskOpinion.STATUS_REFUSE)){
				if(assignee.equals(opinion.getExeUserId())){
					return true;
				}
			}
		}
		return false;
	}

	@Override
	public String getTitle() {
		return "之前审批过后跳过";
	}
}
